#include<iostream>
#include<unordered_map>
typedef long long ll;
const int N = 2e6 + 10;
ll a[N];
using namespace std;
int main()
{
	unordered_map <ll, ll> mp;
	ll n, m;cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];mp[a[i]]++;
	}
	ll count1 = 0;
	for (int i = 1; i <= n; i++)
	{
		ll b = m + a[i];
		count1 += mp[b];
	}
	cout << count1 << endl;
	return 0;
}
//#include<iostream>
//#include<set>
//using namespace std;
//int main()
//{
//	multiset<int> mp;
//	int n, m;cin >> n >> m;
//	for (int i = 1; i <= n; i++)
//	{
//		int m, x;cin >> x;
//		mp.insert(x);
//	}
//	int count1 = 0;
//	for (auto v : mp)
//	{
//		int b = v + m;
//		int g = mp.count(b);
//		count1 += g;
//	}
//	cout << count1 << endl;
//	return 0;
//}
////#include<iostream>
////const int N = 1e6 + 10;
////int num[N];
////using namespace std;
////int main()
////{
////	int n, m;cin >> n >> m;
////	for (int i = 1; i <= n; i++)
////	{
////		cin >> num[i];
////	}
////	int count = 0;
////	for (int i = 1; i <= n; i++)
////	{
////		int b = num[i];
////		for (int j = 1; j <= n; j++)
////		{
////			if (num[j] == b + m) count++;
////		}
////	}
////	cout << count << endl;
////	return 0;
////}